import axios, { AxiosError, CancelTokenSource } from 'axios';

import { formatRequestParams } from './format';
// import ssoAuth from '@hb/sso-auth2';
declare module 'axios' {
  export interface AxiosRequestConfig {
    noToken?: boolean;
    noValidate?: boolean;
    noGlobalMessage?: boolean;
  }
}

export type StandardResponse<T = unknown> = {
  code?: number;
  errorCode?: number;
  status?: number;
  msg?: string;
  info?: string;
  data: T;
};

export const cancelTokenList: CancelTokenSource[] = [];

const service = axios.create({
  baseURL: "http://127.0.0.1:5000",
  withCredentials: true,  // 允许携带凭证
  headers: {
    'Content-Type': 'application/json',
  },
  timeout: 15000,
});

service.interceptors.request.use((conf) => {
  conf.withCredentials = true;
  return conf;
}, (error) => {
  return Promise.reject(error);
});

service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error: AxiosError) => {
    return Promise.reject(error);
  },
);

export default service;
